// pages/User/me/me.js
var app = getApp();
var Api = require("../../../api/method.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pop: true,
    currentData: 0,
    shouquan: true,
    qrUrl: "",
    nickName: "",
    directNickName: "",
    accountBalance: "",
    paySource: "",
    directCount: "",
    indirectCount: "",
    kaidan: "",
    directAmount: "",
    indirectAmount: "",
    yongjin: "",
    pageNo: 1,
    buyclass: "",
    sjywy:false,
    aheight:"",
    currentDatas:0
  },
  //获取当前滑块的index
  // bindchange: function (e) {
  //   var that = this;
  //   that.setData({
  //     currentData: e.detail.current,
  //     buyclass:"",
  //     pageNo:1
  //   })
  //   this.ownercourse();
  // },
  //点击切换，滑块index赋值
  // checkCurrent: function (e) {
  //   const that = this;
  //   if (that.data.currentData === e.target.dataset.current) {
  //     return false;
  //   } else {
  //     that.setData({
  //       currentData: e.target.dataset.current
  //     })
  //   }
  // },
  //点击切换滑块
  checkCurrent:function(e){
    this.setData({
      currentData: e.target.dataset.current,
      currentDatas: e.target.dataset.current,
      buyclass: "",
      pageNo:1
    });
    this.ownercourse();
  },
  //点击弹框
  logo: function (e) {
    this.setData({
      pop: false
    })
  },
  //账号密码登录
  login: function (e) {
    wx.redirectTo({
      url: "/pages/login/login",
    })
  },
  //隐藏白条弹框
  hideBaitiaoView: function (e) {
    if (e.target.dataset.target == 'self')
      this.setData({
        pop: true
      })
  },
  //提现
  Cashwithdrawal: function (e) {
    console.log(e);
    wx.navigateTo({
      url: "/pages/Salesman/withdraw/withdraw?accountBalance=" + e.target.dataset.accountbalance,
    })
  },
  //订单详情
  orderdetails: function (e) {
    wx.navigateTo({
      url: "/pages/Salesman/Details/Details?orderid=" + e.currentTarget.dataset.orderid,
    })
  },
  //订单详情
  orderdetailstwo: function (e) {
    wx.navigateTo({
      url: "/pages/Salesman/detailstwo/detailstwo?orderid=" + e.currentTarget.dataset.orderid,
    })
  },
  //点击图片二维码
  dada: function (e) {
    var img = [];
    img.push(e.currentTarget.dataset.src);
    wx.previewImage({
      current: e.currentTarget.dataset.src,
      urls: img
    })
  },
  //业务员我的
  Salesmandetail: function (e) {
    let that = this;
    let list = {
    };
    Api.owner(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (res.data.data.directSuperior == null) {
          that.setData({
            sjywy: true
          })
        };
        that.setData({
          directNickName: res.data.data.directSuperior,
          accountBalance: res.data.data.accountBalance,
          paySource: res.data.data.paySource,
          directCount: res.data.data.directCount,
          indirectCount: res.data.data.indirectCount,
          kaidan: res.data.data.directCount + res.data.data.indirectCount,
          directAmount: res.data.data.directAmount,
          indirectAmount: res.data.data.indirectAmount,
          yongjin: res.data.data.directAmount + res.data.data.indirectAmount
        })
      }
    });
  },
  //业务员购课列表
  ownercourse: function (e) {
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      type: Number(that.data.currentData) + 1,
      pageNo: that.data.pageNo,
      pageSize: 10,
    };
    console.log(list);
    Api.ownercourse(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (that.data.pageNo == 1) {
          that.setData({
            buyclass: res.data.data
          })
        } else {
          that.setData({
            buyclass: that.data.buyclass.concat(res.data.data)
          })
        };
        if (res.data.data == "" && that.data.pageNo != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: "none",
            duration: 1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync("user")) {
      this.setData({
        shouquan: true
      })
      this.Salesmandetail();
      this.ownercourse();
    } else {
      this.setData({
        shouquan: false
      })
    };
    this.setData({
      qrUrl: wx.getStorageSync("user").qrUrl,
      nickName: wx.getStorageSync("user").nickName
    })
  },
  //同意授权处理
  likesClick: function (e){
    this.setData({
      shouquan: true
    });
    this.Salesmandetail();
    this.ownercourse();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.editTabBar3();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      pageNo: this.data.pageNo + 1
    });
    this.ownercourse();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})